package com.animations;

import com.beans.BirdBean;
import com.beans.OverBean;
import creator.ui.controller.VoicePlayer;
import creator.ui.graphics.Magicanvas;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Graphics;
import java.io.PrintStream;
import java.util.ArrayList;

public class OverPicAction extends Animation {

  public static boolean isOver = false;
  private OverBean over;

  public void loadBean() {
    this.over = new OverBean();
    getBeans().add(this.over);
  }

  public void paint(Graphics g) {
    g.drawImage(
      this.over.getOver(),
      OverBean.getOverX(),
      OverBean.getOverY0(),
      getMagicanvas()
    );
  }

  public void run() {
    doOver();
  }

  private void doOver() {
    int y = OverBean.getOverY0();
    int sp = 4;
    try {
      long curTime = System.currentTimeMillis();
      while (true) {
        System.out.println("-> Bird is Alive? -" + BirdBean._isAlive());
        if (!BirdBean._isAlive()) {
          VoicePlayer.play("/res/sounds/sfx_swooshing.wav");
          while (y += sp <= OverBean.getOverY1()) {
            OverBean.setOverY0(y);
            if (
              ((curTime - System.currentTimeMillis()) % 28L == 0L) && (sp > 1)
            ) {
              sp--;
            }
            Thread.sleep(4L);
            getMagicanvas().repaint();
          }
          isOver = true;
          break;
        }
        Thread.sleep(500L);
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}
